import React from 'react'
import { FormItem } from '../../../components/VForm/interface'
import VForm from '../../../components/VForm'
import { Button, Form, Select, message } from 'antd'
import { SumbitVehicleInfo } from './service'

export default function VehicleInfo() {
  const [form] = Form.useForm()

  const formItems: FormItem[] = [
   {
      name: 'vehicle_id',
      label: '车牌号',
      required: true,
      rule: { pattern:new RegExp('^[京津沪渝冀豫云辽黑湘皖闽鄂赣甘⽢桂贵琼陕青藏川宁新港澳台苏浙][A-HJ-NP-Z][·][A-HJ-NP-Z0-9]{5,6}$'), message: '请输入正确的车牌号，例如浙A·XD111' },
      type: 'input'
    },
    {
      name: 'driver_id',
      label: '驾驶员工号',
      required: true,
      rule: { len: 4, message: '长度为4位' },
      type: 'input'
    },
    {
      name: 'fleet_id',
      label: '车队号',
      rule: { len: 4, message: '长度为4位' },
      required: true,
      type: 'input'
    },
    {
      name: 'status',
      label: '车辆状态',
      required: true,
      type: 'custom',
      customNode:  <Select options={[{ value: '空闲', label: '空闲' }, { value: '出车', label: '出车' }, { value: '维修', label: '维修' }]}/>
    
    },
    {
      name: 'branch',
      label: '品牌',
      required: true,
      type: 'input'
    },
    {
      name: 'type',
      label: '类型',
      required: true,
      type: 'custom',
      customNode:  <Select options={[{ value: '货车', label: '货车' }, { value: '轿车', label: '轿车' }, { value: '大巴车', label: '大巴车' }]}/>
    },
    {
      name: 'model',
      label: '具体车型',
      required: true,
      type: 'input'
    },
    {
      name: 'mileage',
      label: '里程',
      required: true,
      type: 'input'
   }
  ]
  const handleSumbit = async () => {
    const values=form.getFieldsValue();
    /** 接口 */
    await SumbitVehicleInfo(values).then(res=>{
      if(res.data.result==="SUCCESS"){
        message.success('提交成功');
      }
      else{
        message.error(res.data.message);
      }
    })
  }
  return (
    <div className="Vform-container">
      <div className="Vform">
        <VForm formItems={formItems} form={form} />
      </div>

      <div className="sumbit-btn">
        <Button type="primary" onClick={handleSumbit}>
          提交
        </Button>
      </div>
    </div>
  )
}
